package com.imu.purse.modules.trade.dao;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.imu.core.base.BaseMapper;
import com.imu.purse.modules.bitcoin.form.BitcoinForm;
import com.imu.purse.modules.trade.entity.FundEntity;
import com.imu.purse.modules.trade.entity.FundMergeDetailEntity;

/**
 * 
 * @author sunhongwei
 * @email sunhongwei@jshijian.com
 * @date 2018-03-31 12:04:14
 * Copyright (c) 2017 武汉极时间科技有限公司 版权所有 
 * Jshijian aloha CO.,LTD. All Rights Reserved. 
 */
public interface FundMapper extends BaseMapper<FundEntity>
{
	/**
     * 分页查询
     * @param entity 页号
     * @return
     */
	@Select({
		"<script>",
		    "SELECT i.id,",
					"i.user_id, ",
					"IFNULL(i.money,0) money, ",
					"IFNULL(i.lock_money,0) lock_money, ",
					"i.money_address, ",
					"i.time_create, ",
					"i.time_update, ",
					"IFNULL(i.FROZEN_MONEY,0) FROZEN_MONEY, ",
					"IFNULL(i.BJ,0) BJ, ",
					"IFNULL(i.BTC,0) BTC, ",
					"IFNULL(i.FCG,0) FCG, ",
					"IFNULL(i.HBC,0) HBC, ",
					"IFNULL(i.HBB,0) HBB, ",
					"IFNULL(i.ICO,0) ICO, ",
					"IFNULL(i.ETH,0) ETH, ",
					"IFNULL(i.FEN,0) FEN, ",
					"IFNULL(i.COWRY,0) COWRY, ",
					"IFNULL(i.LOCK_BJ,0) LOCK_BJ, ",
					"IFNULL(i.LOCK_FCG,0) LOCK_FCG, ",
					"IFNULL(i.LOCK_ICO,0) LOCK_ICO, ",
					"IFNULL(i.LOCK_ETH,0) LOCK_ETH, ",
					"IFNULL(i.LOCK_COWRY,0) LOCK_COWRY, ",
					"iu.phone ",
		    "FROM imu_fund i, imu_user iu ",
		    "WHERE i.user_id = iu.id AND i.user_id is not null ",
		    "<when test = 'sts != null and !sts.isEmpty()'>",
		    	"AND i.time_create &gt;= #{sts} ",
		    "</when>",
		    "<when test = 'ets != null and !ets.isEmpty()'>",
				"AND i.time_create &lt;= #{ets} ",
			"</when>",

			"<when test = 'p != null and !p.isEmpty()'>",
				"AND iu.phone = #{p} ",
			"</when>",
			"<when test = 'userId != null'>",
				"AND i.USER_ID = #{userId}",
			"</when>",
			"<when test = 'money != null and  !equalsf.isEmpty()  and  equalsf ==0 and ytfType !=null and ytfType ==0 '>",
			"AND i.money &lt; #{money}",
			"</when>",
			"<when test =  'money != null and  !equalsf.isEmpty()  and equalsf ==1  and ytfType ==0'>",
			"AND i.money &gt; #{money}",
			"</when>",
			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==2 and ytfType ==0 '>",
			"AND i.money &lt;= #{money}",
			"</when>",
			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==3 and ytfType ==0 '>",
			"AND i.money &gt;= #{money}",
			"</when>",
			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==4  and ytfType ==0 '>",
			"AND i.money = #{money}",
			"</when>",

			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==0 and ytfType !=null and ytfType ==1 '>",
			"AND i.ETH &lt; #{money}",
			"</when>",
			"<when test =  'money != null and  !equalsf.isEmpty()  and equalsf ==1  and ytfType ==1'>",
			"AND i.ETH &gt; #{money}",
			"</when>",
			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==2 and ytfType ==1 '>",
			"AND i.ETH &lt;= #{money}",
			"</when>",
			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==3 and ytfType ==1 '>",
			"AND i.ETH &gt;= #{money}",
			"</when>",
			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==4  and ytfType ==1 '>",
			"AND i.ETH = #{money}",
			"</when>",

			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==0 and ytfType !=null and ytfType ==2 '>",
			"AND i.BJ &lt; #{money}",
			"</when>",
			"<when test =  'money != null and  !equalsf.isEmpty()  and equalsf ==1  and ytfType ==2'>",
			"AND i.BJ &gt; #{money}",
			"</when>",
			"<when test = 'money != null and  !equalsf.isEmpty()  and  !equalsf.isEmpty()  and equalsf ==2 and ytfType ==2 '>",
			"AND i.BJ &lt;= #{money}",
			"</when>",
			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==3 and ytfType ==2 '>",
			"AND i.BJ &gt;= #{money}",
			"</when>",
			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==4  and ytfType ==2 '>",
			"AND i.BJ = #{money}",
			"</when>",

			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==0 and ytfType !=null and ytfType ==3 '>",
			"AND i.LOCK_ETH &lt; #{money}",
			"</when>",
			"<when test =  'money != null and  !equalsf.isEmpty()  and equalsf ==1  and ytfType ==3'>",
			"AND i.LOCK_ETH &gt; #{money}",
			"</when>",
			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==2 and ytfType ==3 '>",
			"AND i.LOCK_ETH &lt;= #{money}",
			"</when>",
			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==3 and ytfType ==3 '>",
			"AND i.LOCK_ETH &gt;= #{money}",
			"</when>",
			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==4  and ytfType ==3 '>",
			"AND i.LOCK_ETH = #{money}",
			"</when>",

			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==0 and ytfType !=null and ytfType ==4 '>",
			"AND i.LOCK_CROWRY &lt; #{money}",
			"</when>",
			"<when test =  'money != null and  !equalsf.isEmpty()  and equalsf ==1  and ytfType ==4'>",
			"AND i.LOCK_CROWRY &gt; #{money}",
			"</when>",
			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==2 and ytfType ==4 '>",
			"AND i.LOCK_CROWRY &lt;= #{money}",
			"</when>",
			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==3 and ytfType ==4 '>",
			"AND i.LOCK_CROWRY &gt;= #{money}",
			"</when>",
			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==4  and ytfType ==4 '>",
			"AND i.LOCK_CROWRY = #{money}",
			"</when>",

			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==0 and ytfType !=null and ytfType ==5 '>",
			"AND i.HBC &lt; #{money}",
			"</when>",
			"<when test =  'money != null and  !equalsf.isEmpty()  and  !equalsf.isEmpty()  and equalsf ==1  and ytfType ==5'>",
			"AND i.HBC &gt; #{money}",
			"</when>",
			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==2 and ytfType ==5 '>",
			"AND i.HBC &lt;= #{money}",
			"</when>",
			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==3 and ytfType ==5 '>",
			"AND i.HBC &gt;= #{money}",
			"</when>",
			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==4  and ytfType ==5 '>",
			"AND i.HBC = #{money}",
			"</when>",

			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==0 and ytfType !=null and ytfType ==6 '>",
			"AND i.BTC &lt; #{money}",
			"</when>",
			"<when test =  'money != null and  !equalsf.isEmpty()  and equalsf ==1  and ytfType ==6'>",
			"AND i.BTC &gt; #{money}",
			"</when>",
			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==2 and ytfType ==6 '>",
			"AND i.BTC &lt;= #{money}",
			"</when>",
			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==3 and ytfType ==6 '>",
			"AND i.BTC &gt;= #{money}",
			"</when>",
			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==4  and ytfType ==6 '>",
			"AND i.BTC = #{money}",
			"</when>",

			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==0 and ytfType !=null and ytfType ==7 '>",
			"AND i.LOCK_FCG &lt; #{money}",
			"</when>",
			"<when test =  'money != null and  !equalsf.isEmpty()  and equalsf ==1  and ytfType ==7'>",
			"AND i.LOCK_FCG &gt; #{money}",
			"</when>",
			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==2 and ytfType ==7 '>",
			"AND i.LOCK_FCG &lt;= #{money}",
			"</when>",
			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==3 and ytfType ==7 '>",
			"AND i.LOCK_FCG &gt;= #{money}",
			"</when>",
			"<when test = 'money != null and  !equalsf.isEmpty()  and equalsf ==4  and ytfType ==7 '>",
			"AND i.LOCK_FCG = #{money}",
			"</when>",
		    "ORDER BY i.time_create DESC",
    	"</script>"
	})
    public List<FundEntity> findByPage(final FundEntity entity);
	
	/**
     * 分页查询
     * @param entity 页号
     * @return
     */
	@Select({
		"<script>",
		    "SELECT i.id,",
					"i.user_id, ",
					"IFNULL(i.money,0) money, ",
					"IFNULL(i.lock_money,0) lock_money, ",
					"i.money_address, ",
					"i.time_create, ",
					"i.time_update, ",
					"IFNULL(i.FROZEN_MONEY,0) FROZEN_MONEY, ",
					"IFNULL(i.BJ,0) BJ, ",
					"IFNULL(i.BTC,0) BTC, ",
					"IFNULL(i.FCG,0) FCG, ",
					"IFNULL(i.HBC,0) HBC, ",
					"IFNULL(i.HBB,0) HBB, ",
					"IFNULL(i.ICO,0) ICO, ",
					"IFNULL(i.ETH,0) ETH, ",
					"IFNULL(i.FEN,0) FEN, ",
					"IFNULL(i.COWRY,0) COWRY, ",
					"IFNULL(i.LOCK_BJ,0) LOCK_BJ, ",
					"IFNULL(i.LOCK_FCG,0) LOCK_FCG, ",
					"IFNULL(i.LOCK_ICO,0) LOCK_ICO, ",
					"IFNULL(i.LOCK_ETH,0) LOCK_ETH, ",
					"IFNULL(i.LOCK_COWRY,0) LOCK_COWRY, ",
					"iu.phone ",
		    "FROM imu_rwb_fund i, imu_user iu ",
		    "WHERE i.user_id = iu.id AND i.user_id is not null ",
		    "<when test = 'sts != null and !sts.isEmpty()'>",
		    	"AND i.time_create &gt;= #{sts} ",
		    "</when>",
		    "<when test = 'ets != null and !ets.isEmpty()'>",
				"AND i.time_create &lt;= #{ets} ",
			"</when>",
			"<when test = 'p != null and !p.isEmpty()'>",
				"AND iu.phone = #{p} ",
			"</when>",
		    "ORDER BY i.time_create DESC",
    	"</script>"
	})
    public List<FundEntity> findPageOld(final FundEntity entity);
	
	/****
	 * 更新用户钱包
	 * @param entity
	 */
	@Update({"update imu_fund "
	 		+ "set money = IFNULL(money,0) + #{money},"
	 		+     "lock_money = IFNULL(lock_money,0) + #{money},"
	 		+     "time_update = #{timeUpdate} "
	 		+ "where user_id = #{userId}" })
	public int upMoney(final FundEntity entity);

	@Update({"update imu_fund "
			+ "set bj = IFNULL(bj,0) + #{bj},"
			+     "time_update = #{timeUpdate} "
			+ "where user_id = #{userId}" })
	public int upBjMoney(final FundEntity entity);
	
	/****
	 * 更新用户钱包
	 * @param entity
	 */
	@Update({"update imu_fund "
	 		+ "set money = IFNULL(money,0) + #{money},"
	 		+     "time_update = #{timeUpdate} "
	 		+ "where user_id = #{userId}" })
	public int moMoney(final FundEntity entity);
	
	/**
	 * 根据用户ID获取数据
	 * */
	@Select({"<script>",
		    "SELECT i.id,",
			"i.user_id, ",
			"IFNULL(i.money,0) money, ",
			"IFNULL(i.lock_money,0) lock_money, ",
			"i.money_address, ",
			"i.time_create, ",
			"i.time_update, ",
			"IFNULL(i.FROZEN_MONEY,0) FROZEN_MONEY, ",
			"IFNULL(i.BJ,0) BJ, ",
			"IFNULL(i.BTC,0) BTC, ",
			"IFNULL(i.FCG,0) FCG, ",
			"IFNULL(i.HBC,0) HBC, ",
			"IFNULL(i.HBB,0) HBB, ",
			"IFNULL(i.ICO,0) ICO, ",
			"IFNULL(i.ETH,0) ETH, ",
			"IFNULL(i.FEN,0) FEN, ",
			"IFNULL(i.COWRY,0) COWRY, ",
			"IFNULL(i.LOCK_BJ,0) LOCK_BJ, ",
			"IFNULL(i.LOCK_FCG,0) LOCK_FCG, ",
			"IFNULL(i.LOCK_ICO,0) LOCK_ICO, ",
			"IFNULL(i.LOCK_ETH,0) LOCK_ETH, ",
			"IFNULL(i.LOCK_COWRY,0) LOCK_COWRY ",
		    "FROM imu_fund i ",
		    "WHERE i.user_id = #{userId}",
			
    	"</script>"})
	public FundEntity findByUserId(@Param("userId") final Long userId);
	
	/**
	 * 更新冻结钱包
	 * @param entity
	 * @return
	 */
	@Update({
		"update imu_fund "
		 		+ "set frozen_money = IFNULL(frozen_money,0) + #{frozenMoney},"
		 		+     "time_update = #{timeUpdate} "
		 		+ "where user_id = #{userId}" 
	})
	public int moFrozenMoney(final FundEntity entity);


	/**
	 * 不同核心钱包转账，针对转出人
	 * @param form
	 * @return
	 */
	@Update({
		"update imu_fund set money = IFNULL(money,0) + #{amount} + #{fee}," +
				"frozen_money = IFNULL(frozen_money,0) + #{amount} + #{fee}," +
				"time_update = FROM_UNIXTIME(#{curTime}) "
				+ " where user_id = #{userId}"
	})
	public int modByUId(BitcoinForm form);

	/**
	 * 不同核心钱包转账，针对转入人
	 * @param form
	 * @return
	 */
	@Update({
			"update imu_fund set money = IFNULL(money,0) + #{amount} + #{fee}," +
					"time_update = FROM_UNIXTIME(#{curTime}) "
					+ " where user_id = #{userId}"
	})
	public int modNoByUId(BitcoinForm form);


	/**
	 * 同一个核心钱包间转账
	 * @param entity
	 * @return
	 */
	@Update({
			"update imu_fund set money = IFNULL(money,0) + #{money}," +
					" time_update = #{timeUpdate} "
					+ " where user_id = #{userId}"
	})
	public int modMoneyByUId(final FundEntity entity);
	
	/**
	 * 内部转账修改金额（转出）
	 * @param entity
	 * @return
	 */
	@Update({
		"update imu_fund "
		 		+ "set money = IFNULL(money,0) - #{money} "
		 		+ "where user_id = #{userId}" 
	})
	public int reduceMoney(final FundEntity entity);
	/**
	 * 内部转账修改金额（转入）
	 * @param entity
	 * @return
	 */
	@Update({
		"update imu_fund "
		 		+ "set money = IFNULL(money,0) + #{money} "
		 		+ "where user_id = #{userId}" 
	})
	public int addMoney(final FundEntity entity);

	@Update({
			"update imu_fund set money_address = #{moneyAddress},password = #{password}" +
					",time_update = #{timeUpdate} where id = #{id}"

	})
	public int upAddressById(final FundEntity entity);

	/**
	 * 修改以太坊转出用户账户金额
	 * @param entity
	 * @return
	 */
	@Update({
			"update imu_fund set money = IFNULL(money,0) - #{money},frozen_money = IFNULL(frozen_money,0) - #{money} "
				+",time_update = #{timeUpdate} where user_id = #{userId}"
	})
	public int upYtfOutByUId(final FundEntity entity);

	/**
	 * 合并用户大小账号的金额
	 * @param entity
	 * @return
	 */
	@Update({
		"UPDATE imu_fund f INNER JOIN (SELECT * FROM imu_fund f2 WHERE f2.`USER_ID` = #{payUserId}) f3  " +
				"SET f.`BJ` = IFNULL(f.`BJ`,0) + IFNULL(f3.`BJ`,0),f.`BTC` = IFNULL(f.`BTC`,0) + IFNULL(f3.`BTC`,0)," +
				"f.`COWRY` = IFNULL(f.`COWRY`,0) + IFNULL(f3.`COWRY`,0)," +
				"f.`ETH` = IFNULL(f.`ETH`,0) + IFNULL(f3.`ETH`,0),f.`FCG` = IFNULL(f.`FCG`,0) + IFNULL(f3.`FCG`,0)," +
				"f.`FROZEN_MONEY` = IFNULL(f.`FROZEN_MONEY`,0) + IFNULL(f3.`FROZEN_MONEY`,0)," +
				"f.`HBB` = IFNULL(f.`HBB`,0) + IFNULL(f3.`HBB`,0),f.`HBC` = IFNULL(f.`HBC`,0) + IFNULL(f3.`HBC`,0)," +
				"f.`ICO` = IFNULL(f.`ICO`,0) + IFNULL(f3.`ICO`,0),f.`LOCK_BJ` = IFNULL(f.`LOCK_BJ`,0) + IFNULL(f3.`LOCK_BJ`,0)," +
				"f.`LOCK_COWRY` = IFNULL(f.`LOCK_COWRY`,0) + IFNULL(f3.`LOCK_COWRY`,0)," +
				"f.`LOCK_ETH` = IFNULL(f.`LOCK_ETH`,0) + IFNULL(f3.`LOCK_ETH`,0)," +
				"f.`LOCK_FCG` = IFNULL(f.`LOCK_FCG`,0) + IFNULL(f3.`LOCK_FCG`,0)," +
				"f.`LOCK_ICO` = IFNULL(f.`LOCK_ICO`,0) + IFNULL(f3.`LOCK_ICO`,0)," +
				"f.`LOCK_MONEY` = IFNULL(f.`LOCK_MONEY`,0) + IFNULL(f3.`LOCK_MONEY`,0)," +
				"f.`FEN` = IFNULL(f.`FEN`,0) + IFNULL(f3.fen,0),f.`MONEY` = IFNULL(f.`MONEY`,0) + IFNULL(f3.money,0),f.time_update=#{timeUpdate} " +
				"WHERE f.`USER_ID` = #{recUserId}"
	})
	public int mergeFund(final FundMergeDetailEntity entity);

	/**
	 * 合并账号时，转出账号的金额清零
	 * @param entity
	 * @return
	 */
	@Update({
		"UPDATE imu_fund f SET f.`BJ` = 0,f.`BTC` = 0,f.`COWRY` = 0," +
				"f.`ETH` = 0,f.`FCG` = 0,f.`FROZEN_MONEY` = 0," +
				"f.`HBB` = 0,f.`HBC` = 0,f.`ICO` = 0,f.`LOCK_BJ` = 0," +
				"f.`LOCK_COWRY` = 0,f.`LOCK_ETH` = 0,f.`LOCK_FCG` = 0," +
				"f.`LOCK_ICO` = 0,f.`LOCK_MONEY` = 0,f.`MONEY`=0," +
				"f.`FEN`=0,f.`TIME_UPDATE` = #{timeUpdate} WHERE f.`USER_ID` = #{payUserId}"
	})
	public int mergeClearFund(final FundMergeDetailEntity entity);
	
	/**
	 * 私募修改
	 * @param entity
	 * @return
	 */
	@Update({
		"<script>",
			"update imu_fund" ,
				"<set>",
					"<if test='null != ytfType and ytfType == 0'>money = IFNULL(money,0) + #{money},</if>\n" ,
					"<if test='null != ytfType and ytfType == 12'>lock_money = IFNULL(lock_money,0) + #{money},</if>\n" ,
					"<if test='null != ytfType and ytfType == 2'>bj = IFNULL(bj,0) + #{money} ,</if>\n" ,
					"<if test='null != ytfType and ytfType == 11'>lock_bj = IFNULL(lock_bj,0) + #{money} ,</if>\n" ,
					"<if test='null != ytfType and ytfType == 3'>ico = IFNULL(ico,0) + #{money},</if>\n",
					"<if test='null != ytfType and ytfType == 14'>lock_ico = IFNULL(lock_ico,0) + #{money},</if>\n",
					"<if test='null != ytfType and ytfType == 4'>lock_eth = IFNULL(lock_eth,0) + #{money},</if>\n" ,
					"<if test='null != ytfType and ytfType == 15'>eth = IFNULL(eth,0) + #{money},</if>\n" ,
					"<if test='null != ytfType and ytfType == 5'>lock_cowry = IFNULL(lock_cowry,0) + #{money},</if>\n" ,
					"<if test='null != ytfType and ytfType == 16'>cowry = IFNULL(cowry,0) + #{money},</if>\n" ,
					"<if test='null != ytfType and ytfType == 6'>hbc = IFNULL(hbc,0) + #{money},</if>\n" ,
					"<if test='null != ytfType and ytfType == 9'>hbb = IFNULL(hbb,0) + #{money},</if>\n" ,
					"<if test='null != ytfType and ytfType == 8'>fcg = IFNULL(fcg,0) + #{money},</if>\n" ,
					"<if test='null != ytfType and ytfType == 13'>lock_fcg = IFNULL(lock_fcg,0) + #{money},</if>\n" ,
					"<if test='null != ytfType and ytfType == 7'>btc = IFNULL(btc,0) + #{money},</if>\n" ,
					"<if test='null != ytfType and ytfType == 10'>fen = IFNULL(fen,0) + #{money},</if>\n" ,
					"time_update = #{timeUpdate} ",
				"</set>" +
			"where user_id = #{userId}",
		"</script>"
	})
	public int up(final FundEntity entity);

	/**
	 * 私募修改
	 * @param entity
	 * @return
	 */
	@Update({
		"<script>",
			"update imu_fund" ,
				"<set>",
					"<if test='null != money and 0 != money'>money = IFNULL(money,0) + #{money},</if>\n" ,
					"<if test='null != lockMoney and 0 != lockMoney'>lock_money = IFNULL(lock_money,0) + #{lockMoney},</if>\n" ,
					"<if test='null != bj and 0 != bj'>bj = IFNULL(bj,0) + #{bj} ,</if>\n" ,
					"<if test='null != lockbj and 0 != lockbj'>lock_bj = IFNULL(lock_bj,0) + #{lockbj} ,</if>\n" ,
					"<if test='null != ico and 0 != ico'>ico = IFNULL(ico,0) + #{ico},</if>\n",
					"<if test='null != lockico and 0 != lockico'>lock_ico = IFNULL(lock_ico,0) + #{lockico},</if>\n",
					"<if test='null != eth and 0 != eth'>eth = IFNULL(eth,0) + #{eth},</if>\n" ,
					"<if test='null != locketh and 0 != locketh'>lock_eth = IFNULL(lock_eth,0) + #{locketh},</if>\n" ,
					"<if test='null != cowry and 0 != cowry'>cowry = IFNULL(cowry,0) + #{cowry},</if>\n" ,
					"<if test='null != lockcowry and 0 != lockcowry'>lock_cowry = IFNULL(lock_cowry,0) + #{lockcowry},</if>\n" ,
					"<if test='null != hbc and 0 != hbc'>hbc = IFNULL(hbc,0) + #{hbc},</if>\n" ,
					"<if test='null != hbb and 0 != hbb'>hbb = IFNULL(hbb,0) + #{hbb},</if>\n" ,
					"<if test='null != fcg and 0 != fcg'>fcg = IFNULL(fcg,0) + #{fcg},</if>\n" ,
					"<if test='null != lockfcg and 0 != lockfcg'>lock_fcg = IFNULL(lock_fcg,0) + #{lockfcg},</if>\n" ,
					"<if test='null != btc and 0 != btc'>btc = IFNULL(btc,0) + #{btc},</if>\n" ,
					"<if test='null != fen and 0 != fen'>fen = IFNULL(fen,0) + #{fen},</if>\n" ,
					"time_update = #{timeUpdate} ",
				"</set>" +
			"where user_id = #{userId}",
		"</script>"
	})
	public int upPri(final FundEntity entity);

	/**
	 * 分页查询
	 * @param entity 页号
	 * @return
	 */
	@Select({
			"<script>",
			"SELECT f.id,",
			"i.id as user_id, ",
			"f.money_address, ",
			"i.phone ",
			"FROM imu_user i left join imu_fund f on i.id = f.user_id ",
			" WHERE f.money_address is null and mod(i.id,10) = #{mod}",
			" ORDER BY i.TIME_CREATE DESC",
			"</script>"
	})
	public List<FundEntity> findAdressData(final FundEntity entity);


	@Select(
		{
			"<script>",
				"SELECT f.id,",
				"f.user_id, ",
				"f.money_address, ",
				"i.phone ",
				"FROM imu_user i , imu_fund f ",
				" WHERE f.id = #{id} and i.phone = #{phone}",
			"</script>"
		}
	)
	public FundEntity findByIdAndPhone(final FundEntity entity);
}
